#include<bits/stdc++.h>
using namespace std;

void fun(int n, vector<string> number, vector<string> name, string SN, string FN) {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!(number[i].find(SN) == 0 || name[i].find(FN) == 0))
			ans++;
	}

	cout << ans << endl;
	for (int i = 0; i < n; i++) {
		if (number[i].find(SN) == 0 || name[i].find(FN) == 0)
			cout << number[i] << " " << name[i] << endl;
		else
			cout << "ZhangSan" << endl;
	}
	return ;
}

signed main() {
	int n;
	cin >> n;
	vector<string> number(n), name(n);
	for (int i = 1; i <= n; i++) {
		cin >> number[i - 1] >> name[i - 1];
	}
	string FN, SN;
	cin >> SN >> FN;
	fun(n, number, name, SN, FN);
	return 0;
}
